package org.budo.redis.jdbc.driver;

import java.sql.SQLException;
import java.util.concurrent.atomic.AtomicInteger;

import org.budo.jdbc.driver.AbstractBudoJdbcPreparedStatement;

/**
 * @author lmw
 */
public class BudoRedisJdbcPreparedStatement extends AbstractBudoJdbcPreparedStatement {
    /**
     * 当前读取到的参数的顺序
     */
    private AtomicInteger parameterIndex = new AtomicInteger(0);

    /**
     * 将parameterIndex加1后返回，初次调用返回1，对应PreparedStatement.setString(1, "")
     */
    public Integer incrementAndGetParameterIndex() {
        return this.parameterIndex.incrementAndGet();
    }

    @Override
    public void clearParameters() throws SQLException {
        super.clearParameters();

        this.parameterIndex = new AtomicInteger(0);
    }

    @Override
    public void close() throws SQLException {
        super.close();

        this.parameterIndex = null;
    }

    @Override
    public String toString() {
        return super.toString()  // 
                + ", statement=" + this.getJdbcStatement() //
                + ", parameters=" + this.getParameterMap();
    }
}
